﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection" />
    <title>店铺每日目标</title>
    <script src="js/jquery/jquery-1.8.1.min.js" type="text/javascript"></script>
    <script src="js/config.js" type="text/javascript" charset="utf-8"></script>
    <link href="css/style.css" rel="stylesheet" type="text/css" charset="utf-8" />
    <link href="css/btnsty.css" rel="stylesheet" type="text/css" charset="utf-8" />
    <link href="css/editform.css" rel="stylesheet" type="text/css" charset="utf-8" />
    <link href="css/global.css" rel="stylesheet" type="text/css" charset="utf-8" />
    <script src="js/Toast.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" charset="utf-8" src="js/barcodescanner.js"></script>
    <script src="js/laydate.js" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8">
        var pageindex = 0;
        var pagecount = 10;

        $(function () {
            laydate.skin('molv'); //切换皮肤，请查看skins下面皮肤库
            GetStockList();
            $("#btnSave").live("click", function () {
                if ($("#shoplist option:checked").val() == "0") {
                    showtoast("请选择店铺！", null, 100, 100);
                    return;
                }
                if ($("#txtdate").val() == "") {
                    showtoast("请输入日期！", null, 100, 100);
                    return;
                }
                if ($("#txttargetamt").val() == "") {
                    showtoast("请输入目标！", null, 100, 100);
                    return;
                }
                CheckDayTarget();
            });

            $("#loadMore").live("click", function () {
                GetDayTargetPageList($("#shoplist option:checked").val());
            });
        });
        function CheckDayTarget() {
            $.ajax({
                url: url_path + "/ajaxdata/ShopTarget.aspx",
                type: "POST",
                data: { aciton: 'CheckDayTarget', shopid: $("#shoplist option:checked").val(), targetdate: $("#txtdate").val()
                },
                timeout: 30000,
                dataType: "text",
                success: function (data) {
                    var msg = $.trim(data);
                    if (msg == "SUCCESS") {
                        showtoast("已经设置过今日目标！", null, 100, 100);
                        return;
                    } else {
                        SaveDayTarget();
                    }
                },
                error: function () {
                    showtoast("通讯超时,请检查网络.", null, 100, 100);
                }
            });
        }
        function SaveDayTarget() {
            $.ajax({
                url: url_path + "/ajaxdata/ShopTarget.aspx",
                type: "POST",
                data: { aciton: 'SaveDayTarget', shopid: $("#shoplist option:checked").val(),
                    shopname: $("#shoplist option:checked").text(), targetdate: $("#txtdate").val(),
                    clientcount: $("#txtclientcount").val(), targetamt: $("#txttargetamt").val()
                },
                timeout: 30000,
                dataType: "text",
                success: function (data) {
                    var msg = $.trim(data);
                    if (msg == "ERROR") {
                        alert("数据保存出错！");
                    } else {
                        showtoast("数据保存成功！", null, 100, 100);
                        GetDayTargetList($("#shoplist option:checked").val());
                    }
                },
                error: function () {
                    showtoast("通讯超时,请检查网络.", null, 100, 100);
                }
            });
        }
        function GetStockList() {
            USER_ID = localStorage.getItem("UserID");
            $.ajax({
                url: url_path + "/ajaxdata/Default.aspx",
                type: "POST",
                data: { aciton: 'GetShopList', userid: USER_ID },
                timeout: 30000,
                dataType: "text",
                success: function (data) {
                    var msg = $.trim(data);
                    if (msg == "NO_DATA") {
                        alert("您没有任何店仓权限，请联系管理员！");
                    } else {
                        var orderObj = JSON.parse(msg);
                        var html = "";
                        for (var i = 0; i < orderObj.length; i++) {
                            html += '<option value="' + orderObj[i].shopid + '">' + orderObj[i].shopname + '</option>'
                        }
                        $("#shoplist").html(html);
                        $("#shoplist").selectindex = 0;
                    }
                    GetDayTargetList($("#shoplist option:checked").val());
                },
                error: function () {
                    showtoast("通讯超时,请检查网络.", null, 100, 100);
                }
            });
        }
        function GetDayTargetList(shopid) {
            $.ajax({
                url: url_path + "/ajaxdata/ShopTarget.aspx",
                type: "POST",
                data: { aciton: 'GetDayTargetList', shopid: shopid, pagecount: pagecount },
                timeout: 30000,
                dataType: "text",
                success: function (data) {
                    var msg = $.trim(data);
                    var html = "";
                    if (msg == "NO_DATA") {
                        html = '<li class="btnlist"><div>'
                        + '暂无记录！</div></li>';
                    } else {
                        var orderObj = JSON.parse(msg);
                        for (var i = 0; i < orderObj.length; i++) {
                            html += '<li class="btnlist"><div>'
                                + '日期：' + orderObj[i].targetdate
                                + '<span>目标额：' + orderObj[i].targetamt + '</span>元'
                                + '</div></li>'
                        }
                    }
                    $("#datalist").html(html);
                },
                error: function () {
                    showtoast("通讯超时,请检查网络.", null, 100, 100);
                }
            });
        }
        function GetDayTargetPageList(shopid) {
            $.ajax({
                url: url_path + "/ajaxdata/ShopTarget.aspx",
                type: "POST",
                data: { aciton: 'GetDayTargetPageList', shopid: shopid, pageindex: ++pageindex, pagecount: pagecount },
                timeout: 30000,
                dataType: "text",
                success: function (data) {
                    var msg = $.trim(data);
                    var html = "";
                    if (msg == "NO_DATA") {
                        showtoast("没有数据可以加载了！", null, 100, 100);
                    } else {
                        var orderObj = JSON.parse(msg);
                        var li, el;
                        el = document.getElementById('datalist');
                        for (var i = 0; i < orderObj.length; i++) {
                            html = '<div>'
                                + '日期：' + orderObj[i].targetdate
                                + '<span>目标额：' + orderObj[i].targetamt + '</span>元'
                                + '</div>'
                            li = document.createElement("li");
                            li.innerHTML = html;
                            el.appendChild(li, el.childNodes[0]);
                        }
                    }
                },
                error: function () {
                    showtoast("通讯超时,请检查网络.", null, 100, 100);
                }
            });
        }
    </script>
</head>
<body style="background: #efefef;">
    <div id="header" class="head">
        <div class="wrap">
            <i class=" menu_back2"><a href="index.html"></a></i>
            <div class="title">
                <span class="title_d">
                    <p>
                        店铺每日目标</p>
                </span>
                <div class="clear">
                </div>
            </div>
        </div>
        <div class="logo_msk">
        </div>
    </div>
    <div id="container">
        <div id="content">
            <div style="position: relative; background: #fff; margin: 8px; border: 1px solid #ddd;">
                <ul class="input-group2">
                    <li><strong>店铺：</strong><hr />
                        <select id="shoplist">
                            <option value="0">数据加载中...</option>
                        </select></li>
                    <li><strong>日期：</strong><hr />
                        <input id="txtdate" class="laydate-icon" value="" onclick="laydate({ elem: '#txtdate' });"
                            placeholder="点击选择日期" /></li>
                    <li><strong>今日目标：</strong><hr />
                        <input id="txttargetamt" class="ipt ipt-sku" type="text" placeholder="输入目标金额" /></li>
                    <li><strong>今日客流量：</strong><hr />
                        <input id="txtclientcount" class="ipt ipt-sku" type="text" placeholder="输入客户流量" /></li>
                </ul>
            </div>
            <div class="mod_btns">
                <a id="btnSave" class="mod_btn bg_2" href="#">保存</a>
            </div>
            <div style="margin: 3px; padding: 5px; background-color: #ededed; border-radius: 5px;">
                <div style="font-size: 15px;">
                    <span style="color: #ff0000;"><strong>历史数据列表：</strong> </span>
                </div>
                <ul id="datalist" class="dlist">
                    <!--<li class="btnlist">
                    <div>
                        开始日期：2016-02-01&nbsp;&nbsp;&nbsp; 截止日期：2016-02-01&nbsp;&nbsp;&nbsp;目标额：<span>5000000</span>元
                    </div>
                </li>-->
                </ul>
                <!-- <div id="pullUp">
                    <span class="pullUpIcon"></span><span class="pullUpLabel">上拉加载更多...</span>
                </div>-->
                <div id="loadMore" style="background-color: #DDD; color: #555; line-height: 35px;
                    text-align: center;">
                    <span>加载更多数据</span>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
